package com.paradogs.demo.logic.manager;

import com.paradogs.demo.logic.manager.base.BaseManager;
import com.paradogs.framework.common.dao.InventoryDao;
import com.paradogs.framework.common.entity.Inventory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: yumi
 * @date: 2023/11/30  15:21
 * @Description: TODO
 */
@Slf4j
@Component
@Scope("prototype")
public class InventoryManager extends BaseManager<Inventory, InventoryDao> {

    public void addItem(Integer itemId, Integer count) {
        Inventory data = getData();
        Map<Integer, Integer> inventory = data.getInventory();
        if (!inventory.containsKey(itemId)) {
            inventory.put(itemId, 0);
        }
        inventory.put(itemId, count + inventory.get(itemId));
        updateData(data);
    }
}
